<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="There are four common ways you can display the data in your taxonomies in addition to the automatic taxonomy pages created by hugo using the list templates:
 For a given piece of content, you can list the terms attached For a given piece of content, you can list other content with the same term You can list all terms for a taxonomy You can list all taxonomies (with their terms)  1.">
        <link rel="alternate" href="https://www.feiyangkeji.com/feed.xml" type="application/rss+xml" title="阳阳学编程">
        <link rel="icon" href="https://www.feiyangkeji.com/favicon.ico">
        <title>Displaying Taxonomies - 阳阳学编程</title>
        <link rel="stylesheet" href="https://www.feiyangkeji.com/css/highlight.js.min.css">
        <link rel="stylesheet" href="https://www.feiyangkeji.com/css/bootstrap.min.css">
        <link rel="stylesheet" href="https://www.feiyangkeji.com/css/bootstrap-theme.css">
        <link rel="stylesheet" href="https://www.feiyangkeji.com/css/font-awesome/css/font-awesome.min.css" />
        
        <link rel="stylesheet" href="https://www.feiyangkeji.com/css/hugo-org.css">
    </head>

<body role="document">
    <nav class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="https://www.feiyangkeji.com/">阳阳学编程</a>
            </div>
            <div id="navbar" class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    
                    <li ><a href="https://www.feiyangkeji.com/">主页</a></li>
                    <li ><a href="https://www.feiyangkeji.com/doc">固件下载</a></li>
                   
                    
                    <li ><a href="https://www.feiyangkeji.com/post/">文章列表</a></li>
                    
                    <li ><a href="https://www.feiyangkeji.com/theme/">开源项目</a></li>
                    
                    <li ><a href="https://www.feiyangkeji.com/showcase/">免费资源</a></li>
                    
                    <li ><a href="https://www.feiyangkeji.com/donate/">关于</a></li>
                    

                </ul>
            </div>
        </div>
    </nav>



<div class="container-fluid">

<div class="row">
    <div class="col-xs-12 col-sm-3">
        
<aside>
    <div class="well">
        
        <div class="pull-right">智能开关固件 v2.0.1(开发中...)</div>
        <ul class="nav nav-list">
            
            
            
            <li>
                <label class="tree-toggle nav-header">快速开始</label>
                <ul class="nav nav-list">
                    
                    <li>
                        <a href="https://www.feiyangkeji.com/doc/overview/quickstart/">Quickstart</a>
                    </li>
                    
                </ul>
            
            </li>
            
            
            <li>
                <label class="tree-toggle nav-header">内容(Content)</label>
                <ul class="nav nav-list">
                    
                    <li>
                        <a href="https://www.feiyangkeji.com/doc/content/archetypes/">Archetypes</a>
                    </li>
                    
                    <li>
                        <a href="https://www.feiyangkeji.com/doc/content/example_en/">Example</a>
                    </li>
                    
                </ul>
            
            </li>
            
            
            <li>
                <label class="tree-toggle nav-header">分类(Taxonomies)</label>
                <ul class="nav nav-list">
                    
                    <li>
                        <a href="https://www.feiyangkeji.com/doc/taxonomies/displaying/">Displaying</a>
                    </li>
                    
                </ul>
            
            </li>
            
            
            <li>
                <label class="tree-toggle nav-header">常见问题</label>
                <ul class="nav nav-list">
                    
                    <li>
                        <a href="https://www.feiyangkeji.com/doc/troubleshooting/overview/">Troubleshooting Overview</a>
                    </li>
                    
                </ul>
            
            </li>
            
            
            <li>
                <label class="tree-toggle nav-header">关于Hugo</label>
                <ul class="nav nav-list">
                    
                    <li>
                        <a href="https://www.feiyangkeji.com/doc/meta/license/">License</a>
                    </li>
                    
                </ul>
            
            </li>
            
            
            <li>
                <label class="tree-toggle nav-header">community</label>
                <ul class="nav nav-list">
                    
                    <li>
                        <a href="https://www.feiyangkeji.com/doc/community/mailing-list/">Mailing List</a>
                    </li>
                    
                    <li>
                        <a href="http://discuss.gohugo.io">讨论社区</a>
                    </li>
                    
                </ul>
            
            </li>
            
            
            <li>
                <label class="tree-toggle nav-header">extras</label>
                <ul class="nav nav-list">
                    
                    <li>
                        <a href="https://www.feiyangkeji.com/doc/extras/shortcodes/">Shortcodes</a>
                    </li>
                    
                    <li>
                        <a href="https://www.feiyangkeji.com/doc/extras/toc_en/">Table of Contents</a>
                    </li>
                    
                </ul>
            
            </li>
            
            
            <li>
                <label class="tree-toggle nav-header">layout</label>
                <ul class="nav nav-list">
                    
                    <li>
                        <a href="https://www.feiyangkeji.com/doc/templates/terms_en/">Taxonomy Terms</a>
                    </li>
                    
                    <li>
                        <a href="https://www.feiyangkeji.com/doc/templates/sitemap/">Sitemap</a>
                    </li>
                    
                </ul>
            
            </li>
            
            
            <li>
                <label class="tree-toggle nav-header">themes</label>
                <ul class="nav nav-list">
                    
                    <li>
                        <a href="https://www.feiyangkeji.com/doc/themes/creation/">Creating a Theme</a>
                    </li>
                    
                </ul>
            
            </li>
            
            
            <li>
                <label class="tree-toggle nav-header">tutorials</label>
                <ul class="nav nav-list">
                    
                    <li>
                        <a href="https://www.feiyangkeji.com/doc/tutorials/automated-deployments/">Automated deployments</a>
                    </li>
                    
                </ul>
            
            </li>
            
            
              
            <li>
                <a href="https://github.com/coderzh/feiyangkeji.com/edit/master/content/doc/taxonomies/displaying_en.md" target="blank">
                <i class='fa fa-edit'></i>修改此文章</a>
            </li>
            
            
        </ul>
    </div>
</aside>


    </div>
    <div class="col-xs-12 col-sm-9 doc-main">
        <main role="main">
            <article>
                <a id="title"></a>
                <h1 class="doc-entry-title">Displaying Taxonomies</h1>
                <section>
                    <p>There are four common ways you can display the data in your
taxonomies in addition to the automatic taxonomy pages created by hugo
using the <a href="https://www.feiyangkeji.com/doc/templates/list/">list templates</a>:</p>
<ol>
<li>For a given piece of content, you can list the terms attached</li>
<li>For a given piece of content, you can list other content with the same
term</li>
<li>You can list all terms for a taxonomy</li>
<li>You can list all taxonomies (with their terms)</li>
</ol>
<h2 id="1-displaying-taxonomy-terms-assigned-to-this-content">1. Displaying taxonomy terms assigned to this content</h2>
<p>Within your content templates, you may wish to display
the taxonomies that that piece of content is assigned to.</p>
<p>Because we are leveraging the front matter system to
define taxonomies for content, the taxonomies assigned to
each content piece are located in the usual place
(.Params.<code>plural</code>).</p>
<h3 id="example">Example</h3>
<pre><code>&lt;ul id=&quot;tags&quot;&gt;
  {{ range .Params.tags }}
    &lt;li&gt;&lt;a href=&quot;tags/{{ . | urlize }}&quot;&gt;{{ . }}&lt;/a&gt; &lt;/li&gt;
  {{ end }}
&lt;/ul&gt;
</code></pre>
<h2 id="2-listing-content-with-the-same-taxonomy-term">2. Listing content with the same taxonomy term</h2>
<p>First, you may be asking why you would use this. If you are using a
taxonomy for something like a series of posts, this is exactly how you
would do it. It’s also an quick and dirty way to show some related
content.</p>
<h3 id="example-1">Example</h3>
<pre><code>&lt;ul&gt;
  {{ range .Site.Taxonomies.series.golang }}
    &lt;li&gt;&lt;a href=&quot;{{ .URL }}&quot;&gt;{{ .Name }}&lt;/a&gt;&lt;/li&gt;
  {{ end }}
&lt;/ul&gt;
</code></pre>
<h2 id="3-listing-all-content-in-a-given-taxonomy">3. Listing all content in a given taxonomy</h2>
<p>This would be very useful in a sidebar as “featured content”. You could
even have different sections of “featured content” by assigning
different terms to the content.</p>
<h3 id="example-2">Example</h3>
<pre><code>&lt;section id=&quot;menu&quot;&gt;
    &lt;ul&gt;
        {{ range $key, $taxonomy := .Site.Taxonomies.featured }}
        &lt;li&gt; {{ $key }} &lt;/li&gt;
        &lt;ul&gt;
            {{ range $taxonomy.Pages }}
            &lt;li hugo-nav=&quot;{{ .RelPermalink}}&quot;&gt;&lt;a href=&quot;{{ .Permalink}}&quot;&gt; {{ .LinkTitle }} &lt;/a&gt; &lt;/li&gt;
            {{ end }}
        &lt;/ul&gt;
        {{ end }}
    &lt;/ul&gt;
&lt;/section&gt;
</code></pre>
<h2 id="4-rendering-a-sites-taxonomies">4. Rendering a Site&rsquo;s Taxonomies</h2>
<p>If you wish to display the list of all keys for a taxonomy, you can find retrieve
them from the <code>.Site</code> variable which is available on every page.</p>
<p>This may take the form of a tag cloud, a menu or simply a list.</p>
<p>The following example displays all tag keys:</p>
<h3 id="example-3">Example</h3>
<pre><code>&lt;ul id=&quot;all-tags&quot;&gt;
  {{ range $name, $taxonomy := .Site.Taxonomies.tags }}
    &lt;li&gt;&lt;a href=&quot;/tags/{{ $name | urlize }}&quot;&gt;{{ $name }}&lt;/a&gt;&lt;/li&gt;
  {{ end }}
&lt;/ul&gt;
</code></pre>
<h3 id="complete-example">Complete Example</h3>
<p>This example will list all taxonomies, each of their keys and all the content assigned to each key.</p>
<pre><code>&lt;section&gt;
  &lt;ul&gt;
    {{ range $taxonomyname, $taxonomy := .Site.Taxonomies }}
      &lt;li&gt;&lt;a href=&quot;/{{ $taxonomyname | urlize }}&quot;&gt;{{ $taxonomyname }}&lt;/a&gt;
        &lt;ul&gt;
          {{ range $key, $value := $taxonomy }}
          &lt;li&gt; {{ $key }} &lt;/li&gt;
                &lt;ul&gt;
                {{ range $value.Pages }}
                    &lt;li hugo-nav=&quot;{{ .RelPermalink}}&quot;&gt;&lt;a href=&quot;{{ .Permalink}}&quot;&gt; {{ .LinkTitle }} &lt;/a&gt; &lt;/li&gt;
                {{ end }}
                &lt;/ul&gt;
          {{ end }}
        &lt;/ul&gt;
      &lt;/li&gt;
    {{ end }}
  &lt;/ul&gt;
&lt;/section&gt;
</code></pre>

                </section>
            </article>
        </main>
        <br />
        
        <div class="row">
            <div class="col-xs-6 col-sm-6 text-center">
                
                <a href="https://www.feiyangkeji.com/doc/taxonomies/usage">&lt; 上一篇</a>
                
            </div>
            <div class="col-xs-6 col-sm-6 text-center">
                
                <a href="https://www.feiyangkeji.com/doc/taxonomies/templates">下一篇 &gt;</a>
                
            </div>
        </div>
        
    </div> 
</div>



<hr />

<div class="row">
    <div class="col-sm-12">
        
	    <div class="text-center">
        
		    <p class="doc-footer-em"><a href="#">回到顶部↑</a></p>
	    </div>
	</div>
</div>

</div> 

<footer class="doc-footer">
	
    <p>Copyright © <a href="http://www.feiyangkeji.com/"> 北京飞阳信远科技有限公司(京ICP备2021020257号-1 )</a> 2021. Generated by <a href="http://gohugo.io/">Hugo</a></p>
</footer>

<script>
	(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
	(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
	m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
	})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
	ga('create', 'UA-10147768-3', 'auto');
	ga('send', 'pageview');
</script>

<script src="https://www.feiyangkeji.com/js/jquery-1.11.2.min.js"></script>
<script src="https://www.feiyangkeji.com/js/bootstrap.min.js"></script>

<script src="https://www.feiyangkeji.com/js/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script src="https://www.feiyangkeji.com/js/ie10-viewport-bug-workaround.js"></script>

</body>
</html>

